//
//  NYPostMulReplyTableViewCell.m
//  Nooryes
//
//  Created by myPro on 2019/12/31.
//  Copyright © 2019 UUU9. All rights reserved.
//

#import "NYPostMulReplyTableViewCell.h"
#import "NYCommentListModel.h"

@interface NYPostMulReplyTableViewCell()
@property (weak, nonatomic) IBOutlet UIImageView *avatar;
@property (weak, nonatomic) IBOutlet UILabel *author;
@property (weak, nonatomic) IBOutlet UILabel *time;
@property (weak, nonatomic) IBOutlet UILabel *content;
@property (weak, nonatomic) IBOutlet UIView *replyView;
@property (weak, nonatomic) IBOutlet UIButton *moreBtn;
@property (weak, nonatomic) IBOutlet UILabel *reply1;
@property (weak, nonatomic) IBOutlet UILabel *reply2;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *contentHeight;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *replyHeight;
@property (weak, nonatomic) IBOutlet UIImageView *avatar1;
@property (weak, nonatomic) IBOutlet UIImageView *avatar2;
@property (weak, nonatomic) IBOutlet UILabel *author1;
@property (weak, nonatomic) IBOutlet UILabel *author2;

@end


@implementation NYPostMulReplyTableViewCell


+ (instancetype)cellWithTableView:(UITableView *)tableView{
    NYPostMulReplyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kNYPostMulReplyTableViewCell];
    if (cell == nil) {
        cell = [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self) owner:nil options:nil] lastObject];
    }
    
    return cell;
}

-(void)setModel:(CommentListSubModel *)model{
    _model = model;
    [self.avatar sd_setImageWithURL:[NSURL URLWithString:model.img] placeholderImage:[UIImage imageNamed:@"head_default"]];
    self.content.text = model.content;
    self.author.text = model.nickname;
    self.time.text = model.writetime;
    [self.contentHeight setConstant:model.contentHeight];
    [self.replyHeight setConstant:model.replyHeight];
    if (model.replaylist.count > 0) {
        if (model.replaylist.count > 2) {
            [self.moreBtn setTitle:[NSString stringWithFormat:@"共%lu条回复 点击查看",(unsigned long)model.replaylist.count] forState:UIControlStateNormal];
        }
        
        for (int i = 0; i<model.replaylist.count; i++) {
            CommentListSubModel *subModel = model.replaylist[i];
            if (i == 0) {
                self.author1.text = subModel.nickname;
                self.reply1.text = subModel.content;
                [self.avatar1 sd_setImageWithURL:[NSURL URLWithString:subModel.img] placeholderImage:[UIImage imageNamed:@"head_default"]];
            } else if (i == 1){
                self.author2.text = subModel.nickname;
                self.reply2.text = subModel.content;
                [self.avatar2 sd_setImageWithURL:[NSURL URLWithString:subModel.img] placeholderImage:[UIImage imageNamed:@"head_default"]];
            }
        }
    } else {}
    
}
- (IBAction)onReply1:(id)sender { 
    _replyingBlock(_model.replaylist[0].commentid);
}

- (IBAction)onReply2:(id)sender {
    _replyingBlock(_model.replaylist[1].commentid);
}


- (IBAction)onComment:(id)sender {
    _replyingBlock(_model.commentid);
}

- (IBAction)onMoreReply:(id)sender {
    _loadMoreBlock(_indexPath);
}
- (IBAction)onAvatarHost:(id)sender {
    _avatarBlock(_model.userid);
}
- (IBAction)onAvatarFir:(id)sender {
    _avatarBlock(((CommentListSubModel *)_model.replaylist[0]).userid);
    
}
- (IBAction)onAvatarSec:(id)sender {
    _avatarBlock(((CommentListSubModel *)_model.replaylist[1]).userid);
}

@end
